package com.dxp.utils;

import java.security.SecureRandom;
import java.util.Random;

/**
 * @Classname StrUtils
 * @Description TODO
 * @Date 2020/3/25 0:56
 * @Created by fpc
 */
public class StrUtils {
    private static final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyz";
    private static final Random RANDOM = new SecureRandom();


    /**
     * 获取随机字符串 Nonce Str
     *
     * @return String 随机字符串
     */
    public static String generateNonceStr(int length) {
        char[] nonceChars = new char[length];
        for (int index = 0; index < nonceChars.length; ++index) {
            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }
        return new String(nonceChars);
    }
}
